﻿/*
{
"状态":1,
"名称":"修改-菜单资料",
"作者":"陈泽椿",
"创建时间":"2018-06-30",
"功能":"修改-菜单资料",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/
declare @menu_key char(32) , @father_menu char(32) , @menu_code varchar(100), @menu_name varchar(100),@order_index int
declare @menu_power_id varchar(100)
declare @menu_id varchar(10)
declare @port nvarchar(200)

set @menu_key = '{menu_key}'
set @father_menu ='{father_menu}' 
set @menu_code = '{menu_code}'
set @menu_name = '{menu_name}'
set @order_index = '{order_index}'
set @menu_power_id = '{menu_power_id}'
set @menu_id='{menu_id}'
 

--校验信息
if isnull(@menu_name,'')=''
begin 
	RAISERROR ('SQL:菜单名称不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@menu_code,'')=''
begin 
	RAISERROR ('SQL:菜单代码不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@order_index,'')=''
begin 
	RAISERROR ('SQL:菜单序号不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@menu_power_id,'')=''
begin 
	RAISERROR ('SQL:菜单需求权限id不允许为空', 16 ,1 ) ; 
	return 
end 

 
if not Exists(select 1 from y_power where power_id=@menu_power_id)
begin
	RAISERROR ('SQL:菜单需求权限id不存在,请检查', 16 ,1 ) ; 
	return
end 

select @port=port from y_menu where  menu_key=@menu_key

if isnull(@menu_id,'')<>'' and Exists(select 1 from y_menu where menu_id=@menu_id and port=@port and menu_key<>@menu_key)
begin
	RAISERROR ('SQL:菜单id已经存在,请检查', 16 ,1 ) ; 
	return
end 


if  @father_menu=@menu_key
begin 
	RAISERROR ('SQL:父级菜单和子级菜单不允许相同,请检查', 16 ,1 ) ; 
	return
end 
 
update [dbo].[y_menu] set
[father_menu] = @father_menu ,
[menu_code] = @menu_code ,
[menu_name] = @menu_name , 
[order_index] = @order_index , 
[menu_power_id] = @menu_power_id , 
[update_time] = getdate(),
[menu_id]=@menu_id
where [menu_key] = @menu_key